This is meant for things like attack/magic formulas, turn order determination,
status ailment effects, and the like

$07040C - Routine for selecting a random single target
	-If r1 = 0x1, target a monster; if 0x0, target a party member
	-Generates number [0...199]
	-If result = 100 or above target first party member...etc for others
	-If target is dead/stone, reroll
	-When randomly targeting monsters, weigh each position equally

0x71A3C Sleep/Paralysis recovery routine
	Run at the end of each round for every actor that hasn't had a new status effect applied(?) this turn
	(may only apply if the new status effect changed your status effect bubble)
	-So, you can't recover from Sleep/Paralysis straight away
	-If Asleep:
		-Generate a number between 0 and 80
		-Subtract that number from Max HP; if result is positive, recover from sleep and don't check for Stun
	-If Stunned/Paralyzed:
		-Generate a number between 0 and 99
		-If that number was 24 or less, recover from paralysis
	If at least one unit recovered from Sleep/Paralysis, time to redraw bubbles and reprint PC names!
	Exit

0x78B50 - Run for each unit in the turn order? Checks if can act, handles action+targeting
	Stores unit ID to "currently active unit" address
	Recalculates stats for all PCs and monsters
	Does something with CPUSet
	Redraws HP text for PCs
	(Does something else - need to investigate)
	So, seems to handle what needs to happen at the start of a unit's turn

0x797F8 - For a unit, loads up their chosen action, their target, and spell if applicable
	-Handles unit targeting
	-Checks if their chosen target can be targeted, and handles retargeting if needed

0x79B3C - Monster action calcs here; run at the start of a round
  First, zero out  all action/targeting/spell choice stuff in battle data
  Then check if this monster is alive in the first place

  Load monster's entry in AI ID table, and so load AI definition
  Check if this round is an Ambush round; if so, skip lots of following calcs
  If monster is Asleep/Stun/Stone/Dead, also don't cast
  If monster is Confused, set target to a random monster
  Otherwise 

  0x79BEE - Morale checks; if encounter is unrunnable, monsters can't run either
	-Gets (Morale - 1stPCLevel + 0..50); if result is lower than 80, monster will run
	-Unlike in previous versions, which doubles PC1 level

  0x79C66 - Silence check; if Silenced, skip to rolling for special attack
  Otherwise, roll out of 200 vs spell chance
  If roll failed, roll out of 128 vs ability chance (yes, they use different scales!)
  If that roll failed too, just select a PC to target with a physical attack
  Repeat for every monster

0x79D34 - Turn order calculation! Turn order is decided for all 9 monsters and 4 PCs, even dead/non-existent ones
	This code is run at the start of a round (before commands are entered)
  0x79D8E - Loads a character's total AGL, adds rand(0,49), stores to stack...very simple indeed
	-Then sorts the numbers by magnitude, stores the unit IDs in order to stack

0x079F86 - Subtracting spell's MP cost from party member's MP total

0x07A314 - Called at the end of a combat round
	-Put base offset of monster battle data in r9; BattleMem+$5230 in r8
	-Call $7CBA8 (PC Angel Ring check); store number of PCs to regen in r6
	-For every living monster, check if they're in the Regenerating family
	-If so: set their attack effect struct accordingly
	  0x7A382 X, where (MaxHP/X) is added to current HP at the end of each round. Default 1/20.
	  -Store the amount of health to attack effect struct
	  -Increment r6 (# of units regenerating)
	-Return the number of units regenerating

0x07A3CC - End-of-round Poison checks
	-Loop through every live PC checking for Poison
	-If poisoned, set attack effect struct +$0,+$1 to unit's ID; damage by 1/20th of max HP
	-Set effect type to 0x1
	-Count number of poisoned PCs and return that number

0x07A8C2 - Routine used for monsters casting; calls 0x07B568

0x07AB34 - Routine used for spells cast from items; calls 0x07B568

0x07ACEC - Routine for Running
	-For active character, checks if they are alive, have HP, can act etc
	0x7ADB0 - For Running; this part runs down a timer, then moves to:
	0x7ADDC - Loads runner's INT,AGL and LUK and adds together
		-Then...
		-Loads Evade + (Morale-100)/16 for each living monster and adds them together
		-Then divides by number of living monsters: IE, takes the average value
		-Finally, generates a number between 0 and (INT+AGL+LUK)-1
		-Generates 0...(Monster STR-1)
		-If the first is greater than the second, the running succeeds
		-So, let A = Runner's (INT+AGL+LUK)
		-Let B = Average of all Monsters'(Evade + (Morale - 100)/16)
		-Compare rand([0...A[) and rand([0...B[)

0x7B18C - Routine for running physical attack hit and damage calculations
 -Call $07CC58 (check if attacker wields Ultima Weapon)
 0x7B1AC - Base chance to hit, if evasion/accuracy are identical
 0x7B242 - Loads Attack, and moves to r9
 -Call $07CDC0, Rune Axe auto-hit-auto-critical check
 
 0x7B264 - Blind status check; Blind on attacker and defender modify the base hit chance

 0x7B29A - Elemental/racial weakness determination. Note, these do not stack!
	0x7B2B4 - Hit Rate bonus for effective attacks
	0x7B2BE - Attack bonus for effective attacks

 0x7B2C4 - If target is Asleep or Paralyzed, their evade is zero and attacker's Attack increases by 50%
 0x7B2E4 - Where defender's EVA is subtracted from attacker's ACC

 0x7B2F0 - Min/Max hit% for physical attacks, out of 160.

 0x7B314 - Multiplies attacker's base # of hits by the hit multiplier (from Haste, Slow)

 0x7B33E - X, where a number (0..X) is rolled to determine if a strike hits or misses
		-Also used for critical hit calculations

 0x7B350 - For each hit, Damage = Attack + rand(0..Attack) - Defence
		-But, each hit can only have 255 attack
 0x7B394 - Roll for crit, using same random number that the hit roll used
		-But if the attacker has auto-crit, well, just crit
		-If crit, add Attack to damage - Defence is ignored
 0x7B3B8 - Cap overall damage at 9999

 0x7B3CE - For applying statuses from monster attacks; base infliction chance is 0x65
	-Also, if target is a monster don't bother
	If target resists any of the attack's elements, base chance = 0x0
	Chance = (101 - MGR)/200 or 1/200, whichever is higher.
	Above 101 MGR, all status attacks have a mere 0.5% chance per hit of applying
	Applied for each hit

 -Now branch to $07CD0C (Orichalcum checks)
 -Branch to $07CD74 (if target is PC wearing Red Jacket and attack is Fire-element, negate damage)
 -If no hits landed and defender is a PC with a shield, 50% chance to play shield block animation
 -Call $07CB40 - if wearing Elven Cloak, 1/3 chance to block an attack!
 -In attack effect struct, check effect type for bit 0x04 (status effects set)
	-If true, set status effects to defender and place status effect bubble
		-Also check if they're now Dead, Stone, Paralyzed, Asleep
 -If PC attacker,check if the target is targetable;
 if not cancel attack, store 0x90 to attack effect struct +$0C
	-Won't reach here normally...leftover from previous ports?



0x07B568: Spell hit/damage calculations
	-Called on three occasions: PC casting, monster casting and PC invoking magical item
	Loops over every unit in battle to determine hit/damage individually
	Stores spell-related data to stack; each thing of info gets a word to itself:
	[sp + ...]
	[$00] = $00000000 (will be spell damage)
	[$04] = Spell ID
	[$08] = targeting byte of spell
	[$0C] = Stairstep power of spell
	[$10] = Element bits
	[$14] = Spell Type
	[$18] = Base power/accuracy of spell
	[$1C] = Caster's Intellect
	[$20] = some memory pointer
		+$00: Target Unit ID

	0x07B75C: subroutine pointers for each of the 18 spell types - damage, healing, status, etc...
		-several are unused

	effects struct:
	[+$00] = Attacker Unit ID
	[+$01] = Defender Unit ID
	[+$02] = ?
	[+$04] = Damage taken or healing given from the spell (word)
	[+$08] = 01 if target was struck with the spell
	[+$0C] = Effect; bits 0x84 set on successful status effect infliction; 0x10 on miss?
		-0x120 for healing
	[+$10] = Status(es) to be applied, if the spell causes status effects

  0x07B7BC: Code for damage spells:
	r8 = battle damage stats?
	r9 = combatant's general params?
		[r9+0x4C] = target's data?
	-Check if spell is multitarget
	-Check if spell is type 0x2, damage by family
		-If and only if target is in family 0x8, deal damage
	-Load spell accuracy. Add 0x94.
	-Load target's magic resistance, subtract from base damage.
	-Load caster's intellect. If larger than 49(vanilla), do some weirdness.
		-Divide intellect by stairstep threshold (10 in vanilla)
		-Multiply by stairstep power of spell (could do in reverse now: multiply then asr 0x1)
	-Load caster's intellect and luck from [r9+0x48] struct and add them
					formula:
					-A = (Int+Luck)/2 + (Int*Stairstep Power)/10
					-B = Luck/2


	-Branch to 0x696AC:
		-Load word from 0x02001A18; multiply by $6C078965; add 7 then store back
		-Part of the random number generator
	-Take lower halfword of result from above
	-r1 = B; branch to 0x000F2D:
		-Divides lower halfword by B and returns the remainder; = rand[0...B]
	-Adds to calculated damage at [sp]; so, damage = [A...A+B]
	-Loads target's data [r9+0x4C]; for weakness and resistance
	-If resisted, subtract 201 from accuracy and halve base damage
	-If weak to, add 50 to accuracy and multiply base damage by 1.5
	
	-...If neither resisted nor weak to, generate a number between 0 and 200.
		-If this is less than (Spell Accuracy - MDF), add INT/5 to base damage
		-How pointless!
	-Load Spell ID; branch to 0x7CE04:
		-Check for spell cast = Holy and equipped weapon = Sage's Staff (ID 0x40)
		-If so, multiply damage by 1.5
	-If defender is a player character, load defender's MGR:
		-If MGR > 200, reduce damage by half
		-If 200 => MGR > 100, reduce damage by a quarter
		-Else reduce damage by an eighth
	-Cap damage to 9999
	-Store damage to [sp], and defender struct +$04; store 0x1 to def/struct+$08
	-Branch to 0x807CD74 - if target is a PC wearing the Red Jacket being hit with a Fire spell, negate damage
	-Move to the next target

  0x07B960: Code for status inflicting spells (Hold, Death, Sleep...)

  0x07B9DC: Code for Slow,Slowra
	0x07B9F6: Accuracy determination; adds 148 to spell base hit chance

  0x07BA64: Code for Fear


  0x07BADC: Code for healing spells (Cure,Heal,etc):
	-Healing amount = (stairstep + Int)*base power + rand[0...(Target's Luck/2)[
	0x07BB2A is where spell power, INT are loaded

  0x7BCBA: Code for resistance nullifiers (Dispel):
	-Load spell accuracy, add 148; subtract defender's MGR
	-If defender resists spell element(s), subtract 148 accuracy; if weak to, add 50
	-Jumps to stat-changing spell code to roll the random number

  0x7BD02: Code for 300-HP threshold status spells (Stun, Blind, Kill):
	-If target has over 300 hitpoints, spell misses
	-If target already has any of the applied status effects, spell misses
	-If target resists spell's element, spell misses
	-Otherwise, apply status and draw a status ailment bubble

  0x7BD6C: Code for stat-changing spells (buffs and Focus)
	-If spell is Focus/Focara, must pass hit check to have an effect:
		-Chance = 212 - MDF out of 200
		-Spell element has no impact
	-The stat changes themselves are not applied here - this only sets some flags on affected targets.

  0x7BDDE: Code for Excalipur:
	-Store spell's stairstep power as damage
	
-Real effects are handled here:

0x07BE2C: Subroutine for handling effects of stat-changing spells and effects, and others too
	Run for every unit in battle after any spell is used
	Spell types like damage/healing spells don't do anything, and just skip to the next target
	Loads stairstep power, spell type; loads base power and stores to [sp+0x4]
	Indexes to pointer at $7BEE0 with spell type, and jumps to routine pointed at there

	0x7BF40 - Code for status-setting spells

	0x7BFC4 - Code for Slow-type spells
	0x7BFD4 - Code for Morale-draining spells
		-Only applies to monsters, naturally

	0x7BFF0 - Code for status-curing spells
		-Go to target's 'attack effect struct', load ailments to clear, BIC with current ailments
		-Clear status effect bubbles as needed
		-If was not curing Stone, end here
		-Else, branch to $073358

	0x7C054 - Code for DEF boost
	0x7C06E - Code for resistance-adding spells; adds spell's resists to temp resists

	0x7C07A - Code for ATK + ACC boost (Saber formula)

	0x7C0B2 - Code for ATK boost

	0x7C0CC - Routine used for Evade% down spells (Focus, Focara)
		-Subtracts stairstep power from temp.evade value
		-Caps temp. evade penalty at -255 
	0x7C13A - Routine used for Dispel; set element null to 0xFFFF
	0x7C28E - Routine for basic damage spells, and most other spells (skip to next section)

	For all spells:
		-If target was a player unit, and spell ID was between 0x3 and 0x3B, load ASM pointer from
		table at 0x7C2B4; this determines what aura or effects the character gets from the spell, if any
			0x807C398 Yellow aura (Protect)
			0x807C3B0 Multiple images
			0x807C420 Flicker (Invis)
			0x807C494 Yellow aura (NulShock)
			0x807C4AC Red Aura (NulBlaze)
			0x807C4C4 Blue Aura (NulFrost)
			0x807C4DC Grey Aura (NulDeath)
			0x807C4F4 (NulAll)
			0x807C50C Pink Aura (Haste, NulDeath)
			0x807C524 White Aura (Slow)
			0x807C53C (Dispel)
			0x807C550 (None)

$07CB40 - For physical attacks
	-If defender is a PC wearing the Elven Cloak and at least one hit landed...
	-There's a 1/3 chance to nullify the hit!

$07CDC0 - If attacker wields Rune Axe and has at least 25MP, their attack will hit and crit
	(and subtracts 25MP)

$07CBA8 - Goes through every live PC for Angel Ring checks
		-Check if they have the Angel Ring equipped in the Arms slot
		-If so, go to their entry in +$51E0 attack effect struct; store their unitID to +$0,+$1
		-Then load Max HP and divide by 10; store this to attack effect struct
		-Count number of PCs who wil regenerate and return this number

0x7CC58 - Check for weapon of ID 0x29 (Ultima Weapon - HP-based attack power)
	-If wielding it, weapon power = (MHP/10 * HP)/MHP, plus Strength/2
	-Which...seems to be equivalent to HP/10? 

$07CD0C - During physical attack, check if attacker is armed with Orichalcum
	-If so, drain 1/4 of damage done
	-Unless opponent is undead - then reverse damage